<template>
  <div>
    <h3>黑店</h3>
    <SonCode
      v-for="item in list"
      :key="item.id"
      :msg="item"
      @Haggle="Haggle"
    ></SonCode>
  </div>
</template>

<script>
// 引入子组件
import SonCode from './components/黑店/SonCode.vue'

export default {
  components: {
    SonCode,
  },

  data() {
    return {
      list: [
        {
          id: 1,
          proname: '超级好吃棒棒糖',
          proprice: 188,
          low: 160,
          desc: '甜',
        },
        {
          id: 2,
          proname: '超级好吃的大鸡腿',
          proprice: 360,
          low: 320,
          desc: '香',
        },
        { id: 3, proname: '超级无敌冰激凌', proprice: 42, low: 30, desc: '冰' },
      ],
    }
  },
  methods: {
    Haggle(id, num) {
      this.list.forEach((item) => {
        if (item.id === id) {
          item.proprice > item.low ? item.proprice -= num : alert('已经是最低价了')
        }
      })
    },
  },
}
</script>

<style></style>
